﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;


namespace SangoDesktop
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow : Window
	{
		GameHandler Game;
		public MainWindow ( )
		{
			InitializeComponent();
			Game = GameHandler.GetInstance();
		}
		private void Button_Click ( object sender, RoutedEventArgs e )
		{
			if ( this.TextBoxPlayerName.Text != "" )
			{
				GameHandler.RegisterReturns r=Game.Join(this.TextBoxPlayerName.Text);
				if ( r == GameHandler.RegisterReturns.Success )
				{
					this.ShowMessage("Join successed.");
				}
				else if ( r == GameHandler.RegisterReturns.UsedPlayerName )
					this.ShowMessage("This name has been used, please input another one.");
				else
					this.ShowMessage("Unknown error.");
			}
			else
				this.ShowMessage("Please input your player name.");
		}

		private void ShowMessage(string message)
		{
			this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new System.Action(delegate
			{
				this.textBlockMessage.Text = message.Replace("\n", "    ");
				( (Storyboard)this.Resources["StoryboardtextBlockStatus"] ).Begin(this.textBlockMessage);
			}));
		}

		private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
		{
			if ( e.GetPosition(this).Y <= 25 )
				this.DragMove();
		}
	}
}
